package com.sanpu.kxe.business.card.adapter;

import android.graphics.Color;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sanpu.kxe.R;
import com.sanpu.kxe.business.card.bean.BankInfoOutput;
import com.sanpu.kxe.common.interfaces.UrlConstants;
import com.sanpu.kxe.common.utils.CommonUtils;
import com.sanpu.kxe.common.view.BankCardTextView;
import com.sanpu.kxe.jump.imageloader.JKImageLoader;
import com.sanpu.kxe.module.roundview.RoundLinearLayout;

import java.util.ArrayList;

/**
 * Description：银行卡列表适配
 * Created by 薛勇军 on 2019/4/12.
 */

public class BankListAdapter extends BaseQuickAdapter<BankInfoOutput, BaseViewHolder> {

    public BankListAdapter() {
        super(R.layout.item_bank_info, new ArrayList<BankInfoOutput>());
    }

    @Override
    protected void convert(BaseViewHolder helper, BankInfoOutput item) {
        RoundLinearLayout itemView = helper.getView(R.id.item_view);   //item项
        RoundLinearLayout headView = helper.getView(R.id.head_view);
        ImageView icon = helper.getView(R.id.icon);
        TextView name = helper.getView(R.id.name);
//        TextView cardType = helper.getView(R.id.card_type);
        BankCardTextView cardNumber = helper.getView(R.id.card_number);

        name.setText(item.getBankName());
        String bankNo = CommonUtils.secretBankNumber(item.getBankNo());
        try {
            cardNumber.setBankCardText(bankNo);
//            cardType.setText(CommonUtils.checkBankCardType(item.getCardType()));
            JKImageLoader.getInstance().displayImage(mContext, UrlConstants.getBaseUrl() + item.getLogoPath(), icon);

//            int[] colors = {Color.parseColor("#"+item.getCardColorStart()), Color.parseColor("#"+item.getCardColorEnd())};
//            GradientDrawable drawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colors);
//            drawable.setCornerRadius(ScreenUtil.dp2px(3));
//            drawable.setShape(GradientDrawable.RECTANGLE);
//            drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
//            itemView.setBackground(drawable);
            itemView.getDelegate().setStrokeColor(Color.parseColor("#"+item.getCardColorStart()));
            headView.getDelegate().setBackgroundColor(Color.parseColor("#"+item.getCardColorStart()));
        } catch (Exception e) {
            e.printStackTrace();
            if (!TextUtils.isEmpty(bankNo)) {
                cardNumber.setBankCardText(bankNo);
            }
        }
    }
}
